#encoding:utf-8
import re,string
from chinese import *
from pinyin import hanzi2pinyin

class WORD:
	def __init__(self):
		self.chinese=CHINESE()
		self.word=''
		self.filename=''
		
	def get(self,word,filename):
		#文件名词法解析
		self.word=self._convert2en(word)

		self.filename=self._convert2en(filename)
		if self._getContaining(self.filename):
			return True
		
		self.filename=filename
		if self._getAcronym(self.filename):
			return True
			
	def _getContaining(self,filename):
		#包含匹配
		return bool(re.search(self.word, filename, re.IGNORECASE))

	def _getAcronym(self,filename):
		#首字母和汉字拼音首字母匹配
		stren=''
		for str in filename:
			if self._iscnchar(str):
				stren=stren+hanzi2pinyin(str)+' '
			else:
				stren=stren+str
		stren=stren.replace('  ',' ')
		
		list_word=stren.split(' ')
		acronym=''
		for str in list_word:
			if self._iscnchar(str[0]):
				str[0]=get_cn_first_letter(str[0])
			acronym=acronym+str[0]
		return self._getContaining(acronym)
		
	def _iscnchar(self,i):
		#判断是否为汉字
		return 0x4e00<=ord(i)<0x9fa6
		
	def _convert2en(self,word):
		#转换为拼音
		return hanzi2pinyin(word)
		